package cn.edu.fudan.tool;

import cn.edu.fudan.type.Timeseries;
import cn.edu.fudan.type.TwoTuple;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by 80494 on 2017/5/5.
 * In this file, we define different read method from different file types.
 *
 */
public class Read {
    //tested
    public TwoTuple<List<Timeseries>,Integer> readTimeFromUCRFormat(String FilePath)throws Exception{
        List<Timeseries> data = new ArrayList<Timeseries>();
        Integer Nclass =0;
        List<Integer> classlabel= new ArrayList<Integer>();
        BufferedReader bufferedReader = new BufferedReader(new FileReader(FilePath));
        String s = bufferedReader.readLine();
        while(s!=null){
            Timeseries di = new Timeseries();
            int timestamp =0;
            Integer t=Integer.parseInt(s.split(",")[timestamp]);
            if(!classlabel.contains(t)){  //第一个是类标签
                classlabel.add(t);
                Nclass++;
            }
            //timestamp++;
            for(timestamp=1 ;timestamp<s.split(",").length;timestamp++){
                //Timeseries value =new Timeseries();
                di.getTimestamp().add((double)timestamp);
                di.getValue().add(Double.parseDouble(s.split(",")[timestamp]));
                //di(value);
            }
            //System.out.println(di);
            data.add(di);
            s = bufferedReader.readLine();
        }
        bufferedReader.close();
        return new TwoTuple<List<Timeseries>,Integer>(data,Nclass);
    }
}
